{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "d2a75ff2",
   "metadata": {},
   "source": [
    "------\n",
    "* 学习人：纪秋霞\n",
    "* 时间：2021-12-09\n",
    "* week15\n",
    "* 学习线上资源：\n",
    "\n",
    "> 1.[python官方文档](https://python.org/doc)\n",
    "\n",
    "> 2.[老师博客](https://www.cnblogs.com/xuzhichao/p/11570285.html)\n",
    "------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "430b6611",
   "metadata": {},
   "source": [
    "# 上周回顾\n",
    "\n",
    ">1. 函数的定义 ： def\n",
    ">2. 函数名的定义规则-->变量名一样的规则\n",
    ">3. 调用函数的方式: func_name(name)\n",
    ">4. 参数：\n",
    ">>1. 形式参数（定义函数）\n",
    ">>2. 实际参数（调用函数）\n",
    ">>3. 有多个参数时：\n",
    ">>>0. 关键字参数\n",
    ">>>1. 位置参数（调用函数时）---> 关键字参数要均放在末尾（多个不考虑顺序）\n",
    ">>>2. 默认参数（定义函数时）---> 默认参数均放在末尾（多个不考虑顺序）\n",
    "\n",
    "# 本周知识\n",
    "\n",
    "> 1. 函数的返回值\n",
    "> 2. 函数的输入参数类型\n",
    "> 3. 函数的返回参数类型\n",
    "> 4. 模块的概念\n",
    "> 5. 如何创建一个模块，并且调用自己定义的模块"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "898753fd",
   "metadata": {},
   "source": [
    "## 1. 函数的返回值\n",
    "\n",
    "> 1. 返回值关键字： return\n",
    ">> 1. <font style=\"color:red\">**函数一定是有返回值**</font>（无论是什么编程语言）\n",
    ">> 2. 在其他的编程语言中，返回值（return）一定要写，不写会报错!；但是在python中，return可以不写，return 默认为 None\n",
    ">> 3. 返回值一般为函数体运行的结果（result）（函数返回值实践1）；也可以是自定义的函数返回值（实践2）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "1e73e4de",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 函数返回值实践1\n",
    "def get_formatted_name(first_name,last_name):\n",
    "    \"\"\"返回整洁的名字\"\"\"\n",
    "    full_name = first_name + ' '+ last_name\n",
    "#     print(full_name)\n",
    "    return full_name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "d95ef92a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Li Hua'"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "get_formatted_name(\"Li\",\"Hua\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "be9d2cb1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Li Hua\n"
     ]
    }
   ],
   "source": [
    "print(get_formatted_name(\"Li\",\"Hua\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "7b85dd53",
   "metadata": {},
   "outputs": [],
   "source": [
    "####\n",
    "def get_formatted_name(first_name,last_name):\n",
    "    \"\"\"返回整洁的名字\"\"\"\n",
    "    full_name = first_name + ' '+ last_name\n",
    "#     print(full_name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "6370e9d8",
   "metadata": {},
   "outputs": [],
   "source": [
    "get_formatted_name(\"Li\",\"Hua\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "beb96e1b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "None\n"
     ]
    }
   ],
   "source": [
    "print(get_formatted_name(\"Li\",\"Hua\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "b06edcd9",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 函数返回值实践2\n",
    "def log_in(user_name,password):\n",
    "    \"\"\"验证登录信息\"\"\"\n",
    "    if user_name == \"LiHua\" and password == 123456:\n",
    "        return 1\n",
    "    else:\n",
    "        return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "6a7f8bd2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "log_in(\"LiHua\",123456)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "636f98c7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "log_in(\"LiHua\",1234567)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "426e9410",
   "metadata": {},
   "source": [
    "## 2. 函数输入的参数类型\n",
    "\n",
    "> 1. 函数输入的参数\n",
    ">> 1. 函数可以输入复杂的参数(列表，字典，集合，元组等等)：\n",
    ">>> 1. 函数参数为列表\n",
    ">>> 2. 函数参数为字典\n",
    ">>> 3. ...\n",
    "\n",
    "> 2. 函数可以输入不确定个数的参数：\n",
    ">> 1. *args\n",
    ">> 2. ** kwargs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "78fb28ba",
   "metadata": {},
   "outputs": [],
   "source": [
    "def test_A(names):\n",
    "    \"\"\"测试函数参数输入为列表\"\"\"\n",
    "    return names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "e7938466",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Lihua', 'Xiaoming', 'Alex']"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_A([\"Lihua\",\"Xiaoming\",\"Alex\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "e1aa5362",
   "metadata": {},
   "outputs": [],
   "source": [
    "def test_B(person):\n",
    "    \"\"\"测试函数参数输入为字典\"\"\"\n",
    "    return person"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "8c44cc06",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stu_id': 20001, 'age': 18, 'job': 'student'}"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_B({\"stu_id\":20001,\"age\":18,\"job\":\"student\"})"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4b2b9c85",
   "metadata": {},
   "source": [
    "### 2.1 *args (位置参数)\n",
    "> 1. args 可以接受多个数据（单值）\n",
    "> 2. args 将多个数据存在一个**元组**当中，实际还是一个变量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "5e7162ba",
   "metadata": {},
   "outputs": [],
   "source": [
    "# *args\n",
    "def food_ingred(food,*ingreds):\n",
    "    \"\"\"食物配料单\"\"\"\n",
    "    return food,ingreds"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "dfc00682",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('pizza', ('mushroom', 'cheese', 'green peppers'))"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "food_ingred(\"pizza\",\"mushroom\",\"cheese\",\"green peppers\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "2da2e4b3",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "keyword argument repeated (<ipython-input-64-7caa867f93fb>, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-64-7caa867f93fb>\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m    food_ingred(food=\"pizza\",ingreds=\"mushroom\",ingreds=\"cheese\",ingreds=\"green peppers\")\u001b[0m\n\u001b[1;37m                                                ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m keyword argument repeated\n"
     ]
    }
   ],
   "source": [
    "food_ingred(food=\"pizza\",ingreds=\"mushroom\",ingreds=\"cheese\",ingreds=\"green peppers\")\n",
    "# 用 关键字参数 会报错"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "61e857f4",
   "metadata": {},
   "source": [
    "### 2.2 ** kwargs（关键字参数）\n",
    "> 1. kwargs 可以接受多个数据(键值对)==> 关键字参数\n",
    "> 2. kwargs 将多个 键值对 的数据存放在一个**字典**中，实际上还是一个变量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "0751d83f",
   "metadata": {},
   "outputs": [],
   "source": [
    "# **kwargs\n",
    "def person(stud_name,**stud_course):\n",
    "    \"\"\"学生个人信息完善表\"\"\"\n",
    "    return stud_name,stud_course"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "00ccdc9a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('Lihua', {'course_星期一': 'API', 'course_星期二': 'app原型设计'})"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "person(\"Lihua\",course_星期一=\"API\",course_星期二=\"app原型设计\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "1da759ff",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "person() takes 1 positional argument but 3 were given",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-63-a838b23b810e>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mperson\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Lihua\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m\"API\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m\"app原型设计\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m: person() takes 1 positional argument but 3 were given"
     ]
    }
   ],
   "source": [
    "person(\"Lihua\",\"API\",\"app原型设计\")\n",
    "# 用 位置参数 会报错"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cf92a96c",
   "metadata": {},
   "source": [
    "## 3. 函数的输出（返回值）参数类型\n",
    "\n",
    "> 1. 在编程语言中，<font style=\"color:red\">**函数的返回值只能是一个值**</font>\n",
    "> 2. 返回值可以是 字符串、数值、列表、字典等数据（单一值）\n",
    "> 3. python可以输出多个返回值，结果会用一个<font style=\"color:red\">**元组**</font>进行封装并返回。（本质不违背函数的定义）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "dbd116d2",
   "metadata": {},
   "outputs": [],
   "source": [
    "# test1_字符串\n",
    "def test1_return():\n",
    "    \"\"\"测试返回值return为字符串\"\"\"\n",
    "    return \"你好\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "a8c643a7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'你好'"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test1_return()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "d08ae3f0",
   "metadata": {},
   "outputs": [],
   "source": [
    "# test2_数值\n",
    "def test2_return():\n",
    "    \"\"\"测试返回值return为数值\"\"\"\n",
    "    return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "a0fda09f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test2_return()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "713428d2",
   "metadata": {},
   "outputs": [],
   "source": [
    "# test3_列表\n",
    "def test3_return():\n",
    "    \"\"\"测试返回值return为列表\"\"\"\n",
    "    return ['Lihua','Alex','Jack']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "ea7c2de7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Lihua', 'Alex', 'Jack']"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test3_return()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "eb8c9707",
   "metadata": {},
   "outputs": [],
   "source": [
    "# test4_字典\n",
    "def test4_return():\n",
    "    \"\"\"测试返回值return为字典\"\"\"\n",
    "    return {'stu_id':20001,'age':18,'job':'student'}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "d26e66cb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stu_id': 20001, 'age': 18, 'job': 'student'}"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test4_return()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "34b59392",
   "metadata": {},
   "outputs": [],
   "source": [
    "# **********  return 后面写多个值将会返回成元组，仍是一个值，不违背函数在编程思维中的定义\n",
    "def test5_return():\n",
    "    \"\"\"测试返回值return为 多个值的情况\"\"\"\n",
    "    return 18,\"Lihua\",['Lihua','Alex','Jack'],{'stu_id':20001,'age':18,'job':'student'}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "d2a2000c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(18,\n",
       " 'Lihua',\n",
       " ['Lihua', 'Alex', 'Jack'],\n",
       " {'stu_id': 20001, 'age': 18, 'job': 'student'})"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test5_return()\n",
    "# 返回成一个 *元组 tuple*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "8dae2ea3",
   "metadata": {},
   "outputs": [],
   "source": [
    "# **********\n",
    "def test6_return():\n",
    "    \"\"\"测试返回值return为 多个值的情况\"\"\"\n",
    "    return 88,89,90,90"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "dc97e69f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(88, 89, 90, 90)"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test6_return()\n",
    "# 返回成一个 *元组 tuple*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "fda5c969",
   "metadata": {},
   "outputs": [],
   "source": [
    "# test4_字典(拓展)\n",
    "\n",
    "def dict_test(request_header):\n",
    "    \"\"\"测试输入参数为字典\"\"\"\n",
    "    print(request_header)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "03cd1dd7",
   "metadata": {},
   "outputs": [],
   "source": [
    "# https://httpbin.org/get\n",
    "httpbin_get = {\n",
    "  \"args\": {}, \n",
    "  \"headers\": {\n",
    "    \"Accept\": \"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\", \n",
    "    \"Accept-Encoding\": \"gzip, deflate\", \n",
    "    \"Accept-Language\": \"zh-CN,zh;q=0.9\", \n",
    "    \"Host\": \"httpbin.org\", \n",
    "    \"Upgrade-Insecure-Requests\": \"1\", \n",
    "    \"User-Agent\": \"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36\", \n",
    "    \"X-Amzn-Trace-Id\": \"Root=1-61adb9bb-3c9ba8e966c3d5ad6c841e04\"\n",
    "  }, \n",
    "  \"origin\": \"210.21.79.236\", \n",
    "  \"url\": \"http://httpbin.org/get\"\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "eddceabf",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'zh-CN,zh;q=0.9', 'Host': 'httpbin.org', 'Upgrade-Insecure-Requests': '1', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36', 'X-Amzn-Trace-Id': 'Root=1-61adb9bb-3c9ba8e966c3d5ad6c841e04'}\n"
     ]
    }
   ],
   "source": [
    "dict_test(httpbin_get['headers'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "f2d6c9c0",
   "metadata": {},
   "outputs": [],
   "source": [
    "def test4_return():\n",
    "    \"\"\"测试返回值return 为字典\"\"\"\n",
    "    return httpbin_get['headers']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "cb43f8b3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',\n",
       " 'Accept-Encoding': 'gzip, deflate',\n",
       " 'Accept-Language': 'zh-CN,zh;q=0.9',\n",
       " 'Host': 'httpbin.org',\n",
       " 'Upgrade-Insecure-Requests': '1',\n",
       " 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36',\n",
       " 'X-Amzn-Trace-Id': 'Root=1-61adb9bb-3c9ba8e966c3d5ad6c841e04'}"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test4_return()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "39663650",
   "metadata": {},
   "source": [
    "## 4. 模块 \n",
    "\n",
    "> 1. 使用模块可以**隐藏函数的源代码**\n",
    "> 2. 使用的人不需要会底层代码（只需要会使用模块即可）\n",
    "\n",
    "> 3. 模块的使用方法\n",
    ">> 1. import 模块名\n",
    ">>> * 使用： 模块名.函数名\n",
    ">> 2. from 模块名 import 函数名\n",
    ">>> * 使用： 函数名()\n",
    "\n",
    "\n",
    "* 内置模块\n",
    "* 自定义模块"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "c45562da",
   "metadata": {},
   "outputs": [],
   "source": [
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "bdf61486",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2021, tm_mon=12, tm_mday=9, tm_hour=11, tm_min=42, tm_sec=12, tm_wday=3, tm_yday=343, tm_isdst=0)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.localtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "d588c045",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 直接调用模块名\n",
    "import study"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "311c0f24",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'e', 'o'}"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 函数的调用\n",
    "study.search4vowels(\"hello world\")\n",
    "\n",
    "# 省去代码内容—在文件新建 text_file 命名为 .py 文件 — 运用import"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "c2ca0df8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on function news_链接 in module study:\n",
      "\n",
      "news_链接(url, 新闻分类, page)\n",
      "    抓取学校新闻的所有页面链接\n",
      "    url:学校网站的域名链接\n",
      "    新闻分类:学校新闻的分类英文简称\n",
      "    page:你想要抓取的页面尾页\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(study.news_链接)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "b92c9a7b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['https://www.nfu.edu.cn/xxyw/index.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index1.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index2.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index3.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index4.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index5.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index6.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index7.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index8.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index9.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index10.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index11.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index12.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index13.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index14.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index15.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index16.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index17.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index18.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index19.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index20.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index21.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index22.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index23.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index24.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index25.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index26.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index27.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index28.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index29.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index30.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index31.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index32.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index33.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index34.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index35.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index36.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index37.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index38.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index39.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index40.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index41.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index42.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index43.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index44.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index45.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index46.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index47.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index48.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index49.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index50.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index51.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index52.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index53.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index54.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index55.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index56.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index57.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index58.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index59.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index60.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index61.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index62.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index63.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index64.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index65.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index66.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index67.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index68.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index69.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index70.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index71.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index72.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index73.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index74.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index75.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index76.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index77.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index78.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index79.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index80.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index81.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index82.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index83.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index84.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index85.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index86.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index87.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index88.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index89.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index90.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index91.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index92.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index93.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index94.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index95.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index96.htm',\n",
       " 'https://www.nfu.edu.cn/xxyw/index97.htm']"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "study.news_链接('https://www.nfu.edu.cn/','xxyw','98')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "6b0baf39",
   "metadata": {},
   "outputs": [],
   "source": [
    "# from 模块名 import 函数名\n",
    "from time import localtime"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "e8dd126c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2021, tm_mon=12, tm_mday=9, tm_hour=11, tm_min=46, tm_sec=52, tm_wday=3, tm_yday=343, tm_isdst=0)"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "localtime()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5baad0d5",
   "metadata": {},
   "source": [
    "#### 课外拓展\n",
    "* 函数可否调用别的函数 （嵌套）\n",
    "* 函数可否调用自己的函数 （函数的递归）\n",
    "* [学习链接](https://www.cnblogs.com/xuzhichao/p/11570285.html)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ebb71311",
   "metadata": {},
   "source": [
    "#### 课后练习"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "bdf61fde",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Making a 16-inch pizza with the following toppings\n",
      "--pepperoni\n",
      "\n",
      "Making a 12-inch pizza with the following toppings\n",
      "--mushroom\n",
      "--green peppers\n",
      "--extra cheese\n"
     ]
    }
   ],
   "source": [
    "# 导入模块\n",
    "\n",
    "import study #调用模块\n",
    "study.make_pizza(16,'pepperoni')  #调用模块的函数\n",
    "study.make_pizza(12,\"mushroom\",\"green peppers\",\"extra cheese\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "a5b90adf",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Making a 16-inch pizza with the following toppings\n",
      "--pepperoni\n",
      "\n",
      "Making a 12-inch pizza with the following toppings\n",
      "--mushroom\n",
      "--green peppers\n",
      "--extra cheese\n"
     ]
    }
   ],
   "source": [
    "# 使用 as 给函数指定别名\n",
    "\n",
    "from study import make_pizza as mp\n",
    "mp(16,'pepperoni')  #调用模块的函数\n",
    "mp(12,\"mushroom\",\"green peppers\",\"extra cheese\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "142a43e0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Making a 16-inch pizza with the following toppings\n",
      "--pepperoni\n",
      "\n",
      "Making a 12-inch pizza with the following toppings\n",
      "--mushroom\n",
      "--green peppers\n",
      "--extra cheese\n"
     ]
    }
   ],
   "source": [
    "# 使用 as 给模块指定别名\n",
    "\n",
    "import study as s\n",
    "s.make_pizza(16,'pepperoni')  \n",
    "s.make_pizza(12,\"mushroom\",\"green peppers\",\"extra cheese\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "23c7e355",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Making a 16-inch pizza with the following toppings\n",
      "--pepperoni\n",
      "\n",
      "Making a 12-inch pizza with the following toppings\n",
      "--mushroom\n",
      "--green peppers\n",
      "--extra cheese\n"
     ]
    }
   ],
   "source": [
    "# 导入模块中的所有函数\n",
    "# 使用星号（*）运算符可以让Python导入模块中的所有函数：\n",
    "\n",
    "from study import*\n",
    "make_pizza(16,'pepperoni')\n",
    "make_pizza(12,\"mushroom\",\"green peppers\",\"extra cheese\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
